<?php
include_once 'facebook.php';
include_once 'AbstractPicSync.php';
class FacebookSync extends AbtractPicSync
{
	public $appId="151908311533018";
	public $secret="f5e3f2d39fdf14be7d448580e0e2b7d0";
	public $facebook=null;
	public $user=null;
	
	public function  getSession()
	{
		global $facebook,$user;
		
		# Creating the facebook object
		$facebook = new Facebook(array(
    		'appId'  => $appId,
	    	'secret' => $secret,
    		'cookie' => true
		));
		$session=$facebook->getSession();
		if(empty($session))
		{
			 # There's no active session, let's generate one
    		$login_url = $facebook->getLoginUrl(array(  
		    //'req_perms' => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos'));  
			'req_perms' => 'user_photos'));  
	    	header("Location: ".$login_url);	
		}
		else
		{
			$user=$facebook->api('/me');
		}
	}	
	
	
	public function getAlbums()
	{
		$albums=$this->facebook->api('/me/albums?token='.$session['access_token'].'&format=json');
		print_r($albums);
	}
	
	public function addAlbum($albumName)
	{
		$this->facebook->setFileUploadSupport(true);
		$album_details = array(
        'message'=> 'PicSync',
        'name'=> $albumName
		);	
		
		$create_album = $this->facebook->api('/'.$this->facebook->getUser().'/albums', 'post', $album_details);
		$album_uid = $create_album['id'];
		echo $album_uid;
	}
	
	public function deleteAlbum($albumId)
	{
		//TODO
	}
	
	public function uploadPhoto($albumId, $photo)
	{
	
		$upload_photo = $facebook->api('/'.$albumId.'/photos', 'post', $photo);
		echo 'photo added successfully to the album';
	
	}
	
	public function  deletePhoto($albumId, $photoId)
	{
		//TODO
	}
	
	
}

?>